package algotithm.acwing.greedy.test148;

/**
 * @author 25068
 * @Date 2021/6/28 8:50
 */
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        String s1 = reader.readLine();
        System.out.println(s1.length());
        int n = Integer.parseInt(s1);
        int[] arr = new int[n];
        String[] s = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(s[i]);
        }
        Arrays.sort(arr);
        int res = 0;
        int[] dp = new int[n];
        for (int i = 1; i < n; i++) {
            dp[i] = arr[i] + arr[i - 1];
            res += dp[i];
        }
        writer.write(res + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }
}
